﻿using Dapper;
using MediatR;
using System.Text;
using Warehouse.Api.Read.AGCation.Command;
using Warehouse.Domian.Model;
using Warehouse.ErrorCode;
using Warehouse.Infrastructrue.Implenment;

namespace Warehouse.Api.Read.AGCation.Hanlder
{
    public class StockinCommandHanlder : IRequestHandler<StockinCommand, ApiResult<List<Stocking>>>
    {
        DbContext db;
        ILogger<StockinCommandHanlder> logger;

        public StockinCommandHanlder(DbContext db, ILogger<StockinCommandHanlder> logger)
        {
            this.db = db;
            this.logger = logger;
        }
        /// <summary>
        /// 入库的统计数据
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>

        public async  Task<ApiResult<List<Stocking>>> Handle(StockinCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Stocking>> result = new ApiResult<List<Stocking>>();
            try
            {
                var sqlBuilder = new StringBuilder();
                sqlBuilder.Append(@"SELECT * FROM Stocking WHERE IsDeleted =2");
                var sql = await db.DapperConnection.QueryAsync<Stocking>(sqlBuilder.ToString());
                result.Code = ApiEume.Success;
                result.Msg = "统计出库的信息";
                result.Data = sql.ToList();
            }
            catch (Exception ex)
            {

            }
            return result;
        }
    }
}
